﻿/*
 * Creado por SharpDevelop.
 * Usuario: jfacorro
 * Fecha: 18/05/2010
 * Hora: 2:35
 * 
 * Para cambiar esta plantilla use Herramientas | Opciones | Codificación | Editar Encabezados Estándar
 */
using System;
using System.Diagnostics;

namespace TimeMaker
{
	/// <summary>
	/// Description of BmpReader.
	/// </summary>
	public class BpmReader
	{
		private Stopwatch current = null;
		private Stopwatch last = null;
		
		public BpmReader()
		{			
		}
		
		public void tap() 
		{
			if(this.current != null)
			{
				this.current.Stop();
				this.last = this.current;
			}
			
			this.current = new System.Diagnostics.Stopwatch();
			this.current.Start();
		}
		
		public float GetBpm()
		{
			float bpm = 0;
			if(this.last != null)
			{
				float elapsed = (float)this.last.ElapsedTicks / (float)Stopwatch.Frequency;
				if(elapsed > 0)
					bpm = 60 / elapsed;
			}
			return bpm;			
		}
	}
}
